<template>
    <div>
        <h1>{{ msg.hello }}</h1>
        <ElButton :onclick="logout">退出登录</ElButton>
    </div>
</template>

<script setup lang="ts">
import api from '@/api';
import router from '@/router';
import store from '@/store';
import { ElButton, ElNotification } from 'element-plus';
import { ref } from 'vue';

const msg = ref({
    hello: '111'
})

api.hello.hello()
    .then(response => {
        msg.value.hello = response.data.msg
    })
    .catch(error => {
        msg.value.hello = error.data.msg
    });



function logout() {
    api.user.logout()
    .then(response => {
        router.push({ path: '/login' })
        store.commit('setToken', null)
        ElNotification({
            title: 'Success',
            message: response.data.msg,
            type: 'success',
            duration: 1500
        })
    })
    .catch(error => {
        ElNotification({
            title: 'Error',
            message: error.data.msg,
            type: 'error',
            duration: 1500
        })
    });
}
</script>

<style scoped></style>